<template>
  <div class="generate-form">
    <template v-if="gData">
      <GenerateItem
        v-for="(item, index) in gData"
        v-show="!item.hidden"
        :key="index"
        :item="item"
        @checkShow="showCondition(item)"
      ></GenerateItem>
    </template>
  </div>
</template>

<script>
import GenerateItem from './GenerateItem.vue';
import operateMixin from '@/components/GenerateForm/operateMixin';
export default {
  mixins: [operateMixin],
  components: { GenerateItem },
  props: {
    gData: {
      type: Array,
      default: null
    }
  },
  methods: {
    showCondition(changer) {
      this.gData.forEach((item) => {
        if (item.uniteType == 0) {
          if (item.relation == changer.dbField) {
            if (item.relation_value == changer.bindModel) {
              this.$set(item, 'hidden', false);
            } else {
              this.$set(item, 'hidden', true);
            }
          }
        }

        if (item.uniteType == 1) {
          if (item.relation == changer.dbField) {
            let queryParams = {
              list_pointing: item.list_pointing,
              bindModel: changer.bindModel
            };
            this.initOptions(queryParams);
          }
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.generate-form {
  box-sizing: border-box;
  padding: 20px;
  border: 1px solid #dcdfe6;
  border-radius: 5px;
}
</style>
